#!/usr/local/bin/perl -w
use strict;
use warnings;
use utf8;
use lib '../lib';
use NG::Sys::App 'NG::Sys::Loop::EVDaemon';
use NG::Chat::Client::Proxy;

my $app = new NG::Sys::App(logger=>"daemon",config_list=>["chat_admin"]);

$app->run;


sub on_prepare_loop {
	my ($app) = @_;

	if($app->{'sock-connect'} && !$app->arg->{http}){
		require NG::Chat::Client::Sock;
		$app->{'client-connect'} = NG::Chat::Client::Sock::Create($app);
	}elsif($app->{'http-connect'}){
		require NG::Chat::Client::Http;
		$app->{'client-connect'} = NG::Chat::Client::Http::Create($app);
	}else{
		die "need connect";
	}

	$app->{'client-input'} = new NG::Chat::Client::Proxy($app->{'client-connect'},$app);
}

sub on_after_loop {
	my ($app) = @_;
	(delete $app->{'client-input'})->cleanup;
	(delete $app->{'client-connect'})->cleanup;
	$app->on_after_loop;
}
